package pl.javarsovia.javarsovia4android.adapters;

import static pl.javarsovia.javarsovia4android.util.UIUtils.*;

import java.util.List;

import pl.javarsovia.R;
import pl.javarsovia.javarsovia4android.domain.Speaker;
import pl.javarsovia.javarsovia4android.util.ImageManager;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;

/**
 * @author mgrzechocinski
 * @since 2010-06-13
 */
public class SpeakersListAdapter extends BaseAdapter {
	private Context ctx;
	private List<Speaker> speakers;

	public SpeakersListAdapter(Context ctx, List<Speaker> speakers) {
		this.ctx = ctx;
		this.speakers = speakers;
	}

	@Override
	public int getCount() {
		return speakers.size();
	}

	@Override
	public Object getItem(int i) {
		return speakers.get(i);
	}

	@Override
	public long getItemId(int i) {
		return i;
	}

	@Override
	public View getView(int i, View view, ViewGroup viewGroup) {
		if (view == null) {
			final LayoutInflater layoutInflater = LayoutInflater.from(ctx);
			view = layoutInflater.inflate(R.layout.speakers_row, viewGroup, false);
		}
		Speaker speaker = speakers.get(i);
		fillTextView(view, R.id.speaker_name, speaker.getName());
		ImageView speakerPhoto = (ImageView) view.findViewById(R.id.speaker_photo);
		speakerPhoto.setImageDrawable(ImageManager.getInstance().getImage(speaker.getPhotoUrl()));
		// ImageBitmap(ImageManager.getInstance().getImage(speaker.getPhotoUrl()));
		return view;
	}
}
